package com.example.juejincheck.utils;

import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;

/**
 * @author yangkun
 * @description
 * @date 2023年02月10日 15:31
 */
public class FileUtils {
    //将File对象转换为byte[]的形式
    public static byte[] FileTobyte(File file){
        FileInputStream fileInputStream = null;
        byte[] imgData = null;

        try {

            imgData = new byte[(int) file.length()];
            //read file into bytes[]
            fileInputStream = new FileInputStream(file);
            fileInputStream.read(imgData);

        } catch (IOException e) {
            e.printStackTrace();
        } finally {
            if (fileInputStream != null) {
                try {
                    fileInputStream.close();
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }

        }
        return imgData;
    }
}
